package com.keldian.myqq.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import android.os.Handler;

import com.keldian.myqq.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;


/**
 * Created by Administrator on 15-11-17.
 */
public class WhatsNewDoor extends Activity{

    @ViewInject(R.id.imageLeft)
    ImageView mImageLeft;

    @ViewInject(R.id.imageRight)
    ImageView mImageRight;

    @ViewInject(R.id.anim_text)
    TextView anim_text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.whats_door);
        ViewUtils.inject(this);
        initView();
    }

    private void initView() {
        AnimationSet anim  = new AnimationSet(true);

        TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, -1f, Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 0f);


        ta.setDuration(2000);

        anim.setStartOffset(800);

        anim.addAnimation(ta);

        anim.setFillAfter(true);

        mImageLeft.startAnimation(anim);

        //门向右的动画
        AnimationSet anim1  = new AnimationSet(true);

        TranslateAnimation ta2 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 0f);


        ta2.setDuration(1500);

        anim1.setStartOffset(800);

        anim1.addAnimation(ta2);

        anim1.setFillAfter(true);

        mImageRight.startAnimation(anim1);

        AnimationSet anim2 = new AnimationSet(true);
        //文字缩放动画
        ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 3f, 1f, 3f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

        scaleAnimation.setDuration(1000);
        AlphaAnimation alphaAnimation = new AlphaAnimation(1,0.0001f);
        alphaAnimation.setDuration(1500);
        anim2.addAnimation(scaleAnimation);
        anim2.addAnimation(alphaAnimation);

        anim2.setFillAfter(true);
        anim_text.startAnimation(anim2);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent (WhatsNewDoor.this,TabActivity.class);
                startActivity(intent);
                WhatsNewDoor.this.finish();
            }
        }, 2300);
    }
}
